﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Loginaspx : System.Web.UI.Page
{
   // User userSrv = new User();
    MyDataDataContext db = new MyDataDataContext();
    

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            //NewUser.aspx页面传递过来的查询字符串变量name值非空
            if(Request.QueryString["name"]!=null)
            {
                txtName.Text = Request.QueryString["name"];
                lblMsg.Text = "注册成功，请登录！";
            }
        }
    }
    protected void BtnLogin_Click(object sender, EventArgs e)
    {
        User user = (from c in db.User
                             where c.UserNickname == txtName.Text && c.UserPwd == txtPwd.Text
                     select c).FirstOrDefault();
       
        
            if(user!=null)
            {
                Session.Clear();
                Session["UserId"] = user.UserID;
                Session["UserName"] = txtName.Text;
                Response.Redirect("~/Home.aspx");
            }
            else
            {
                lblMsg.Text = "用户名或密码错误！";
            }
        
    }
}